package com.mall.user.constant;

import java.math.BigDecimal;

/**
 * 会员等级常量
 */
public interface UserLevelConstant {

    /**
     * 黑金会员
     */
    Integer BLACK_GOLD = 0;

    /**
     * 白金会员
     */
    Integer PLATINUM = 1;

    /**
     * 普通会员
     */
    Integer REGULAR = 2;

    /**
     * 默认会员等级
     */
    Integer DEFAULT_LEVEL = REGULAR;

    /**
     * 会员等级升级门槛（累计消费金额）
     */
    BigDecimal PLATINUM_THRESHOLD = new BigDecimal("10000.00");
    BigDecimal BLACK_GOLD_THRESHOLD = new BigDecimal("50000.00");

    /**
     * 根据累计消费金额计算应有的会员等级
     */
    static Integer calculateLevel(BigDecimal totalSpent) {
        if (totalSpent == null || totalSpent.compareTo(BigDecimal.ZERO) <= 0) {
            return REGULAR;
        }
        if (totalSpent.compareTo(BLACK_GOLD_THRESHOLD) >= 0) {
            return BLACK_GOLD;
        }
        if (totalSpent.compareTo(PLATINUM_THRESHOLD) >= 0) {
            return PLATINUM;
        }
        return REGULAR;
    }
}
